package com.codeoss.framework.controller;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.codeoss.framework.response.MMenuResponse;
import com.codeoss.framework.service.IMMenuService;

@Controller
@RequestMapping("mmenu")
public class MMenuController {
	@Autowired
	private IMMenuService mMenuService;
	
	@RequestMapping(value = "init", method = RequestMethod.GET)
	@ResponseBody
	public MMenuResponse init(){
		MMenuResponse mMenuResponse=mMenuService.init();
		return mMenuResponse;
	}
	
	@RequestMapping(value = "getPageCodeByMenuId", method = RequestMethod.GET)
	@ResponseBody
	public MMenuResponse getPageCodeByMenuId(@RequestParam("menuId") Long menuId){
		MMenuResponse mMenuResponse=mMenuService.getPageCodeByMenuId(menuId);
		return mMenuResponse;
	}
	
	@RequestMapping(value = "getMenuIconContent", method = RequestMethod.GET)
	@ResponseBody
	public  void getMenuIconContent(@RequestParam("menuId") Long menuId,HttpServletResponse response)throws Exception{
		MMenuResponse mMenuResponse=mMenuService.getMenuIconContent(menuId);
		if(mMenuResponse.getMenuIconContent()!=null) {
			response.getOutputStream().write(mMenuResponse.getMenuIconContent());
		}	
	}
}
